<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>#{msg.regProdotto}</title>
    </h:head>
    <h:body>
        <div class="container">
            <ui:include src="Header.xhtml"/>
            <div class="content">
                <p:messages autoUpdate="true" closable="true"/>
                <h3><p:outputLabel value="#{msg.regProdotto}:"/></h3>
                <h:form id="form1">
                    <h:panelGrid id="grid" columns="2">

                        <p:outputLabel value="#{msg.codiceBarreForm}"/>
                        <p:inputMask required="true" requiredMessage="#{msg.codiceBarreRequestM}" mask="#{msg.codiceBarreMask}" value="#{registrazioneProdotto.codiceBarre}"/>

                        <p:outputLabel value="#{msg.nomeForm}"/>
                        <p:inputText required="true" requiredMessage="#{msg.nomeRequiredM}" value="#{registrazioneProdotto.nome}"/>

                        <p:outputLabel value="#{msg.descrizioneForm}"/>
                        <p:inputTextarea value="#{registrazioneProdotto.descrizione}" maxlength="45" counter="counter" counterTemplate="#{msg.counterTemplate}"/>
                        
                        <h:outputText/>
                        <h:outputText id="counter"/>
                        
                        <p:outputLabel value="#{msg.marchioForm}"/>
                        <p:selectOneMenu required="true" converter="marchioConverter" requiredMessage="#{msg.marchioRequestM}" var="mar" value="#{registrazioneProdotto.marchio}">
                            <f:selectItem itemLabel="#{msg.selMarchio}" itemValue="" noSelectionOption="true"/>
                            <f:selectItems value="#{registrazioneProdotto.marchi}" var="m" itemLabel="#{m.nome}" itemValue="#{m}"/>
                            <p:column>  
                                <p:graphicImage value="#{mar.foto.fotoPath()}" width="50" height="50"/>  
                            </p:column>  
                            <p:column>  
                                #{mar.nome}  
                            </p:column>
                        </p:selectOneMenu>
                        <p:outputLabel value="#{msg.repartoForm}"/>
                        <p:selectOneMenu required="true" converter="repartoConverter" requiredMessage="#{msg.repartoRequestM}" value="#{registrazioneProdotto.reparto}">
                            <f:selectItem itemLabel="#{msg.selReparto}" itemValue="" noSelectionOption="true"/>
                            <f:selectItems value="#{registrazioneProdotto.reparti}" var="r" itemLabel="#{r.nome}" itemValue="#{r}"/>
                        </p:selectOneMenu>
                        <p:outputLabel value="#{msg.fotoTable}:" for="foto"/>
                        <p:selectOneMenu id="foto" required="true" converter="fotoConverter" requiredMessage="#{msg.fotoRequiredM}" var="foto" value="#{registrazioneProdotto.f}">
                            <f:selectItem itemLabel="#{msg.selFoto}" itemValue="" noSelectionOption="true"/>
                            <f:selectItems value="#{registrazioneProdotto.listFoto}" var="f" itemLabel="#{f.nome}" itemValue="#{f}"/>
                            <p:column>  
                                <p:graphicImage value="#{foto.fotoPath()}" width="50" height="50"/>  
                            </p:column>  
                            <p:column>  
                                #{foto.nome}  
                            </p:column>
                        </p:selectOneMenu>
                    </h:panelGrid>
                    <p:commandButton action="#{registrazioneProdotto.registraProdotto()}" update="dataTable,foto" value="#{msg.confermaDati}"/>
                    <hr/>
                    <h3><p:outputLabel value="#{msg.prodottiForm}"/></h3>
                    <p:dataTable id="dataTable" value="#{registrazioneProdotto.prodotti}" var="p" paginator="true" rows="10" 
                                 rowsPerPageTemplate="5,10,15" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                 emptyMessage="#{msg.noProdottiM}">
                        <f:facet name="header">  
                            #{msg.prodottiTable} 
                        </f:facet>  

                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="#{msg.codiceBarreTable}" />  
                            </f:facet>  
                            <h:outputText value="#{p.codiceBarre}" />  
                        </p:column>

                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="#{msg.nomeTable}" />  
                            </f:facet>  
                            <h:outputText value="#{p.nome}" />  
                        </p:column>

                        <p:column style="text-align: center">  
                            <f:facet name="header">  
                                <h:outputText value="#{msg.marchioTable}" />  
                            </f:facet>  
                            <p:graphicImage  value="#{p.marchio.foto.fotoPath()}" width="50" height="50"/>  
                        </p:column>

                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="#{msg.repartoTable}" />  
                            </f:facet>  
                            <h:outputText value="#{p.reparto.nome}" />  
                        </p:column>

                        <p:column style="text-align: center">  
                            <f:facet name="header">  
                                <h:outputText value="#{msg.fotoTable}" />  
                            </f:facet>  
                            <p:graphicImage value="#{p.foto.fotoPath()}" width="120" height="120"/>  
                        </p:column>

                    </p:dataTable>
                </h:form>
            </div>
            <ui:include src="Footer.xhtml"/>
        </div> 
    </h:body>
</html>

